<?php
/**
 * 	Calculates the resources that a city has gained.
 * 	@param int $city the city id
 * 	@param 0..3 $resource recurso: grano, hierro, madera, oro
 * 	@return int El nº de recursos que se le deben aumentar a la ciudad
 */

if (!isset($common)) require_once 'common.php';
require_once 'edificios.php';

function getNewResources($city)
{
	global $debug; 
	
	// Information about the city in question
	$result = mysql_query("SELECT * FROM cities WHERE idcity = ".$city."");
	
	if( !$result)
	{
		die('Error: '. mysql_error());
	}
	$row = mysql_fetch_array($result);
	
	// Calculation
	require 'settings.php'; // Si no lo añado aquí, no toma el valor de la variable
	
	$multiplier=array(1, 1, 1, 1);
	
	for ($i = 0; $i < 4; $i++) 
	{
		for ($j = 0; $j < 4; $j++) 
		{
			$box = (4*$i) + $j;
			
			if ($row["box".$box] > 0)
			{
				if ($debug) echo $row["box".$box]." - ", $row["box".$box."lvl"]." | ";
				$totalResources = GetProduccion($row["box".$box], $row["box".$box."lvl"]);
				if ($debug) var_dump($totalResources);
				$multiplier[$row["box".$box]-1] += $totalResources[$row["box".$box]];
			}
		}
	}
	
	for ($i = 0; $i < 4; $i++) 
	{
		$multiplier[$i] *= $speed;
	}
	
		if ($debug) echo " ( ".$multiplier[0]." ".$multiplier[1]." ".$multiplier[2]." ".$multiplier[3]." ) ";
	
	return $multiplier;
}
?>